/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.zhaocai.service;

import java.util.HashMap;
import java.util.List;

import com.zcm.common.utils.CacheUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zcm.common.utils.CacheUtils;
import com.zcm.common.persistence.Page;
import com.zcm.common.service.CrudService;
import com.zcm.modules.zhaocai.entity.ZcmKanpanData;
import com.zcm.modules.zhaocai.dao.ZcmKanpanDataDao;

/**
 * 看盘数据Service
 * @author www
 * @version 2018-04-22
 */
@Service
@Transactional(readOnly = true)
public class ZcmKanpanDataService extends CrudService<ZcmKanpanDataDao, ZcmKanpanData> {
    public static String CACHE_TYPE = "zcmKanpanData";
	public ZcmKanpanData get(String id) {
		return super.get(id);
	}
	
	public List<ZcmKanpanData> findList(ZcmKanpanData zcmKanpanData) {
		return super.findList(zcmKanpanData);
	}
	
	public Page<ZcmKanpanData> findPage(Page<ZcmKanpanData> page, ZcmKanpanData zcmKanpanData) {
		return super.findPage(page, zcmKanpanData);
	}
	
	@Transactional(readOnly = false)
	public void save(ZcmKanpanData zcmKanpanData) {
		super.save(zcmKanpanData);
		// 更新缓存数据
        CacheUtils.put(CACHE_TYPE,zcmKanpanData.getType(),zcmKanpanData);

	}
	
	@Transactional(readOnly = false)
	public void delete(ZcmKanpanData zcmKanpanData) {
		super.delete(zcmKanpanData);
	}

    public ZcmKanpanData getLatestData(String type) {
        ZcmKanpanData zcmKanpanData = (ZcmKanpanData) CacheUtils.get(CACHE_TYPE,type);
        if(zcmKanpanData == null){
            zcmKanpanData = dao.getLatestData(type);
            if(zcmKanpanData!=null){
                CacheUtils.put(CACHE_TYPE,type,zcmKanpanData);
            }
        }
        return zcmKanpanData;
    }

	public ZcmKanpanData getDataByDay(final String type, final String day) {
		return dao.getDataByDay(new HashMap<String,String>(){{
		    put("type",type);
		    put("day",day);
        }});
	}
}